<%@page import="com.wocai.jrt.orgadmin.issuers.model.Issuers"%>
<%@page import="com.wocai.jrt.admin.common.constant.ComConst"%>
<%@ page language="java" contentType="text/html;charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/inc/taglib.inc" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	Issuers publisher = (Issuers)session.getAttribute(ComConst.CONTEXT_PUBLISHER);
	if (publisher == null) {
		response.sendRedirect("/publisher/login");
		return;
	}
	String currentActionPath = (String)request.getAttribute("currentActionPath");
	request.setAttribute("currentPath",currentActionPath);
%>
		<nav class="navbar-default navbar-static-side" role="navigation">
            <div class="sidebar-collapse">
                <ul class="nav metismenu" id="side-menu">
                    <li class="nav-header">
                        <div class="dropdown profile-element"> <span>
                            <img alt="image" class="img-circle" src="img/profile_small.jpg" />
                             </span>
                            <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">${sessionScope.security_context_publisher.name}</strong>
                             </span> </span> </a>
                            <ul class="dropdown-menu animated fadeInRight m-t-xs">
                                <!-- <li><a href="profile.html">Profile</a></li> -->
                                <li><a href="javascript:;" onclick="updataPassword()">修改密码</a></li>
                                <li class="divider"></li>
                                <li><a href="publisher/logout">退出登录</a></li>
                            </ul>
                        </div>
                        <div class="logo-element">
                            IN+	
                        </div>
                    </li>
                    <li <c:if test="${currentPath eq '/publisher/platform'}"> class="active"</c:if>>
                        <a href="#">
                        	<i class="fa fa-th-large"></i> 
                        	<span class="nav-label">首页</span> 
                        	<span class="fa arrow"></span>
                        </a>
                        <ul class="nav nav-second-level collapse">
                            <li <c:if test="${currentPath eq '/publisher/platform'}">class="active"</c:if>><a href="<c:url value="/publisher/platform"/>">首页</a></li>
                        </ul>
                    </li>
                    <li <c:if test="${currentPath ne '/publisher/platform'}">class="active"</c:if>>
	                    <a href="#"/>
	                    	<i class="fa fa-th-large"></i> 
	                    	<span class="nav-label">产品管理</span> 
	                    	<span class="fa arrow"></span>
	                    </a>
	                    <ul class="nav nav-second-level collapse">
	                        <li <c:if test="${currentPath ne '/publisher/platform'}">class="active"</c:if>><a href="<c:url value="/publisher/product/list"/>">产品回访</a></li>
	                    </ul>
               		 </li>
                </ul>

            </div>
        </nav>
<!-- iCheck -->
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
<div class="modal inmodal fade" id="updateUserPasswd" tabindex="-1" role="dialog"  aria-hidden="true">
    <div class="modal-dialog modal-md">
        <div class="modal-content  ibox-content">
        
        <form method="post" id="updateUserPasswdForm" class="form-horizontal">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">修改密码</h4>
            </div>
            <div class="modal-body">
			<div class="form-group">
	            <label class="col-sm-3 control-label"><font color="red">* </font>旧密码</label>
	                <div class="col-sm-8"><input type="password" id="userOldpasswd" name="userOldpasswd" placeholder="请输入旧密码" class="form-control"></div>
	        </div>									
			<div class="form-group">
	            <label class="col-sm-3 control-label"><font color="red">* </font>新密码</label>
	                <div class="col-sm-8"><input type="password" id="password" name="password" placeholder="请输入新密码" class="form-control"></div>
	        </div>
			<div class="form-group">
	            <label class="col-sm-3 control-label"><font color="red">* </font>确认新密码</label>
	                <div class="col-sm-8"><input type="password" id="passwordConfirm" name="passwordConfirm" placeholder="请再次输入新密码" class="form-control"></div>
	        </div>
    
            </div>
            <div class="modal-footer">
            	<div class="col-sm-4 col-sm-offset-3">
            		<button type="button" class="btn btn-white" data-dismiss="modal">取 消</button>
                	<!-- <button type="submit" id="saveUserPasswd" class="btn btn-primary">确 定</button> -->
                	<button type="button" id="saveUserPasswd" onclick="doUpdata()" class="btn btn-primary">确 定</button>
                </div>
            </div>
		</form>
        </div>

    </div>
</div>

<script type="text/javascript">
	function updataPassword() {
		document.getElementById('userOldpasswd').value="";
		document.getElementById('password').value="";
		document.getElementById('passwordConfirm').value="";
		$('#updateUserPasswd').modal('show');
	}
	function doUpdata() {
		var userOldpasswd = $("#userOldpasswd").val();
		var userNewpasswd = $("#password").val();
		var userRepasswd = $("#passwordConfirm").val();
		if (userOldpasswd.length < 6 || userOldpasswd.length > 20) {
			bootbox.alert("旧密码长度为6-20！");
			return ;
		}
		if (userNewpasswd.length < 6 || userNewpasswd.length > 20) {
			bootbox.alert("新密码长度为6-20！");
			return ;
		}
		if (userRepasswd !== userNewpasswd) {
			bootbox.alert("两次输入的密码不相同！");
			return ;
		}
		var json = $('form#updateUserPasswdForm').serializeJSON();
		$.ajax({
			type : "post",
			contentType : "application/json; charset=UTF-8",
			url : ctx + "/publisher/updateEmpPassword",
			data : json,
			dataType : "json",
			success : function(msg) {
				if (msg.code == 1) {
					$('#updateUserPasswd').modal('hide');
					bootbox.alert("修改密码成功！");
				} else if(msg.code == 2){
					$('#updateUserPasswd').modal('hide');
					bootbox.dialog({
                        message: "修改密码成功，请重新登录！",
                        title: "温馨提示：",
                        buttons: {
                            main: {
                                label: "确定",
                                className: "btn btn-primary",
                                callback: function() {
                                    window.location.reload();
                                }
                            }
                        }
                    });
				}
				else{
					bootbox.alert(msg.message);
				}
			},
			error : function(msg) {
				bootbox.alert(msg.message);
			}
		});
	};
</script>